function zero(number) {
	width = 2;
	width -= number.toString().length;
	if (width > 0)
		return new Array(width + (/\./.test( number ) ? 2 : 1)).join('0') + number;
	return number;
}

function parseDate(input) {
	  var parts = input.match(/(\d+)/g);
	  // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]])
	  return new Date(parts[0], parts[1]-1, parts[2]); // months are 0-based
}

function dateKeypress(event) {
	date = parseDate(this.value)
	k = event.keyCode
	if (k == 38)
		date.setDate(date.getDate() + 1);
	else if (k == 40)
		date.setDate(date.getDate() - 1);
	else
		return '';
	this.value = date.getFullYear() + '-' + zero(date.getMonth() + 1) + '-' + zero(date.getDate());
	return;
}

function bindDateKeys(element) {
	element.onkeypress = dateKeypress;
}